<template>
  <el-form :model="detailForm" ref="detailForm" :rules="rules" :inline="false"
           :label-position="labelPosition">

    <!-- 上传批单 -->
    <el-card class="box-card" shadow="never">

      <div slot="header" class="header-card">
        <span class="header-card-title">上传批单</span>
      </div>

      <el-row :gutter="24">
        <el-col :span="24">
          <el-form-item label="批单:" prop="useSealsOss">
            <image-common v-model="detailForm.useSealsOss" :limit="1" :disabled="!isEdit" :upType="2"/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-card>

  </el-form>
</template>

<script>
export default {
  name: "uploadEndorsement", //上传批单

  props: {
    value: {
      type: Object,
      default: {},
    },
    state: {
      type: String,
      default: "",
    },
  },

  computed: {
    detailForm: {
      get() {
        let that = this;
        const proxy = new Proxy(that.value, {
          get(target, key) {
            return Reflect.get(target, key);
          },
          set(target, key, value) {
            if (value) {
              that.handleClearValidate(key)
            }
            that.$emit("input", {...target, [key]: value});
            return true;
          },
        });
        return proxy;
      },
    },
    labelPosition() {
      if (this.isEdit) {
        return 'top'
      } else {
        return 'right'
      }
    },
    isEdit() {
      let bool;
      switch (this.state) {
        case "write":
          bool = true;
          break;
        case "disabled":
          bool = false;
          break;
        case "readonly":
          bool = false;
          break;
      }
      return bool
    },
  },

  watch: {
    'detailForm.useSealsOss': {
      handler(val) {
        if (val) {
          this.$nextTick(() => {
            this.handleClearValidate('useSealsOss')
          })
        }

      },
      immediate: true,
      deep: true
    }
  },

  data() {
    return {
      isShow: true,
      obj: {},
      shopInsuranceBool: false, //店保
      ourCompanyBool: false, //我司
      activityName: "",
      formId: "",
      bool: false,
      rules: {
        useSealsOss: [
          {required: true, message: '请上传批单', trigger: 'blur'}
        ]
      }
    };
  },

  methods: {
    valid() {
      return new Promise((resolve) => {
        this.$refs.detailForm.validate((valid) => {
          resolve(valid);
        });
      });
    },
    handleClearValidate(str) {
      this.$refs.detailForm.clearValidate(str);
    },
  },
};
</script>


<style lang="scss" scoped>
.box-card {
  font-size: 14px;
  margin-bottom: 16px;
}

.el-form-item {
  width: 70%;
}
</style>
